/**
 * 作者: wgx
 * 日期: 2025-03-18 17:50:54
 * 备注: 用户幸存者派对模块数据
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.monstercity.protocol.Common.PBUserData;
import com.motu.monstercity.server.game.commondata.bag.ItemId;
import com.motu.monstercity.server.game.commondata.maintask.MainTaskConstant;
import com.motu.monstercity.server.game.commondata.rank.RankConstant;
import com.motu.monstercity.server.game.log.MotuLogManager;
import com.motu.monstercity.server.game.logic.MainTaskManager;
import com.motu.monstercity.server.game.logic.RankActManager;
import com.motu.monstercity.server.game.logic.RankManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import io.vertx.core.json.JsonObject;

public class UserFeastInfo extends UserFeastInfoModel {
    public UserFeastInfo() {
        super();
    }

    public JsonObject insert() {
        putResetTime(TimeUtils.getCurTime());
        return super.insert();
    }

    public void reset() {
        if (!TimeUtils.isToday(getResetTime())) {
            putJoinNum(0);
            putResetTime(TimeUtils.getCurTime());
            update();
        }
    }

    // 记录日志并增加积分
    public void addScore(PBUserData.Builder pbUserData, UserInfo userInfo, int num, Object... params) {
        long balance = getScore();// 当前余额
        long dbid = 0;
        MotuLogManager.logItemIncome(userInfo, ItemId.FEAST_SCORE, dbid, balance, num, params);
        super.addScore(num);
        RankManager.updateRank(RankConstant.SERVER_RANK_FEAST, userInfo.getServerId(), userInfo.getId(), getScore(), "0");// 全量更新排行榜
    }
}
